package com.nc.user.controller;

import com.nc.user.dao.FrmDataResourcesDao;
import com.nc.user.dao.FrmDictionDao;
import com.nc.user.model.entity.FrmDataResources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

@Controller
public class ResourcesController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private FrmDataResourcesDao dataResourcesDao;
    @Autowired
    private FrmDictionDao dictionarysDao;

    /*
     *
     * 后台
     *
     * */
    @RequestMapping("home")
    public String home() {
        if (dictionarysDao.findByKeyst("BIND").getVal().equals("NO")) {
            return "redirect:login?is=no";
        }
        return "home";
    }

    /*
     *
     * 登录
     *
     * */
    @RequestMapping("login")
    public String login() {
        return "login";
    }

    /*
     *
     * 页面资源访问
     *
     * */
    @RequestMapping("/vsp/{path}")
    public String vsp(@PathVariable String path) {
        Optional<FrmDataResources> record = dataResourcesDao.findById(path);
        return record.orElseGet(() -> {
            FrmDataResources l = new FrmDataResources();
            l.setUri("404");
            return l;
        }).getUri();
    }
}
